package pl.kozulowski.components {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class CheckBoxGroup extends MovieClip {
		
		private var _boxes:Vector.<MovieClip>;
		private var _selected:Object;
		
		public function CheckBoxGroup(... args) {
			_boxes = new Vector.<MovieClip>();
			var i:int=0;
			for(i; i < args.length; i++) {
				_boxes.push(args[i]);
				_boxes[_boxes.length-1].addEventListener(Event.SELECT, onSelected);
			}
		}
		
		private function onSelected($e:Event):void {
			var i:int=0;
			for(i; i < _boxes.length; i++) {
				_boxes[i].deselect();
			}
			_selected = $e.currentTarget;
			_selected.select();
			dispatchEvent(new Event(Event.SELECT));
		}
		
		public function get data():Object {
			if(_selected) return _selected.data;
			else return null;
		}
		
		public function get selected():Object {
			return _selected;
		}
	}
}